<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var countryDetailsDataGrid;
    $(function() {
        countryDetailsDataGrid = $('#countryDetailsDataGrid').datagrid({
        url : '${path}/admin/countryDetails/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            }
			,{
           	 	width : '100',
           	 	title : 'id',
           	 	field : 'id',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '首都',
           	 	field : 'capital',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '首都英文',
           	 	field : 'capitalEn',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '官方语言',
           	 	field : 'language',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '国家面积',
           	 	field : 'acreage',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '国际人口',
           	 	field : 'population',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '货币',
           	 	field : 'currency',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '时区',
           	 	field : 'timezone',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '宗教',
           	 	field : 'religion',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '安全',
           	 	field : 'security',
           	 	sortable : true
                ${dic:getBusDictListToCase("COUNTRY_TYPE")}

			}
			,{
           	 	width : '100',
           	 	title : '环境',
           	 	field : 'ambient',
           	 	sortable : true,
                ${dic:getBusDictListToCase("COUNTRY_TYPE")}

			}
			,{
           	 	width : '100',
           	 	title : '战乱',
           	 	field : 'war',
           	 	sortable : true,
                ${dic:getBusDictListToCase("COUNTRY_TYPE")}

			}
			,{
           	 	width : '100',
           	 	title : '签证',
           	 	field : 'visa',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '扩展阅读',
           	 	field : 'extend',
           	 	sortable : true,

			}
,
            {
            field : 'action',
            title : '操作',
            width : 140,
            formatter : function(value, row, index) {
                var str = '';
                <shiro:hasPermission name="/admin/countryDetails/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="countryDetails-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="countryDetailsEditFun(\'{0}\');" >编辑</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/admin/countryDetails/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="countryDetails-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="countryDetailsDeleteFun(\'{0}\');" >删除</a>', row.id);
                </shiro:hasPermission>
                return str;
            }
        	}
          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
            $('.countryDetails-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.countryDetails-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#countryDetailsToolbar',
            queryParams: {"countryId": "${countryId}"}
    });
});

/**
 * 添加框
 * @param url
 */
function countryDetailsAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "60%",
        height : "80%",
        href : '${path}/admin/countryDetails/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = countryDetailsDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#countryDetailsAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function countryDetailsEditFun(id) {
    if (id == undefined) {
        var rows = countryDetailsDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        countryDetailsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : "60%",
        height : "80%",
        href :  '${path}/admin/countryDetails/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = countryDetailsDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#countryDetailsEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 删除
 */
 function countryDetailsDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = countryDetailsDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         countryDetailsDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/admin/countryDetails/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     countryDetailsDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}

/**
 * 批量删除
 */
function countryDetailsDeleteIdsFun(){
	var ids = getcountryDetailsSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/countryDetails/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    countryDetailsDataGrid.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getcountryDetailsSelectionsIds(){
	var itemList = $("#countryDetailsDataGrid");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function countryDetailsCleanFun() {
    $('#countryDetailsSearchForm input').val('');
    countryDetailsDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function countryDetailsSearchFun() {
     countryDetailsDataGrid.datagrid('load', $.serializeObject($('#countryDetailsSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
 <%-- <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="countryDetailsSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="countryDetailsSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="countryDetailsCleanFun();">清空</a>
                </div>
                <ul class="list">
                </ul>
            </div>
        </form>
     </div>--%>
 
    <div data-options="region:'center',border:false">
        <table id="countryDetailsDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="countryDetailsToolbar" style="display: none;">
    <%--<shiro:hasPermission name="/admin/countryDetails/add">
        <a onclick="countryDetailsAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>--%>
        <shiro:hasPermission name="/admin/countryDetails/deleteIds">
        <a onclick="countryDetailsDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>